package day_2022_7_to_8.day48;

/**
 * // 链表的奇偶重排
 * @author haomin
 * @date 2022/08/07 10:05
 **/
public class Day23_1_NowCoder_OddEvenList {
    public ListNode oddEvenList (ListNode head) {
        // write code here
        if(head == null || head.next == null) return head;
        ListNode evenList = head.next;
        ListNode odd = head, even = head.next;
        while(odd.next != null && even.next != null){
            odd.next = even.next;
            odd = even.next;
            even.next = odd.next;
            even = odd.next;
        }
        odd.next = evenList;
        return head;
    }
}